package com.boot.controller;

import com.boot.service.FeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * Description:
 *
 * @Autor: Rolin
 * datetime: 05-07-13:19
 */
@RestController
public class NacosConsumerController {

    @Resource
    private RestTemplate restTemplate;

//    这里采用openfeign的 方式来进行微服务的调用
    @Autowired
    private FeignService feignService ;

    @Value("${service-url.nacos-user-service}")
    private String serverURL;

    @GetMapping("/consumer/{id}")
    public String paymentInfo(@PathVariable("id") Long id)
    {
//        这里相当于给 生产者 发送了一个get请求 url为：serverURL+"/payment/nacos/"+id ， 类型为string类型
        return restTemplate.getForObject(serverURL+"/payment/nacos/"+id,String.class);
    }

    @GetMapping("/consumer/feign/{id}")
    public String test02(@PathVariable("id")Integer id ){
        return feignService.getPayment(id);
    }
}
